﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using COFE.Core.Lister;
using COFE.Web;
using COFE.Core;
using COFE.Web.NetClient;

namespace COFE.IO.COFEWS
{
    public class COFEWSStreamProvider : StreamProviderBase
    {
        public COFEWSStreamProvider(COFEWSDirectoryLister lister, string host)
            : base(lister)
        {
            _getStream = (entry, mode, access, share) =>
                {
                    var file = entry as IInternalFileInfoExA;

                    if (!file.IsPropertySupported(COFEWSProperties.StreamUri))
                        throw new NotSupportedException();
                    var streamUri =
                        file.GetProperty(COFEWSProperties.StreamUri).ValueAsString;

                    if (mode == System.IO.FileMode.Open)
                        return COFEWSShared.NetClient.Get(host + streamUri)
                            .GetResponseStream();

                    throw new NotSupportedException();
                };

        }
    }
}
